package com.mangix.scheduler;

import com.mangix.core.MangixNode;

/**
 * Created by Ahan on 2014/8/6.
 */
public class MangixScheduler {

    private MangixNode node;
    private MangixReporter reporter;
    private MangixStabilize stabilize;
    private MangixDiskChecker diskChecker;

    public MangixScheduler(MangixNode node) {
        this.node = node;
        this.reporter = new MangixReporter(node);
        this.stabilize = new MangixStabilize(node);
        this.diskChecker = new MangixDiskChecker(node);
    }

    public void start() {
        reporter.start();
        stabilize.start();
        diskChecker.start();
    }

    /**
     * Once the state of this node is changed, start a stabilize process immediately.
     */
    public void update() {
        synchronized (stabilize) {
            this.stabilize.notify();
        }
        synchronized (reporter) {
            this.reporter.notify();
        }
    }
}
